﻿using CSharp.Basic.Learn.EventBus.Events;
using System;
using System.Threading.Tasks;

namespace CSharp.Basic.Learn.EventBus.Implement
{
  public class UserDeletedEvent : IntegrationEvent
  {
    public Guid UserId { get; set; }
    public string UserName { get; set; }
  }

  public class UserDeletedEventHandler : IIntegrationEventHandler<UserDeletedEvent>
  {
    public Task Handle(UserDeletedEvent @event)
    {
      Console.WriteLine($"事件处理：{nameof(UserDeletedEventHandler)} 用户{@event.UserName}被删除");
      return Task.CompletedTask;
    }
  }

  /// <summary>
  /// 当用户被删除时发送邮件给管理员
  /// </summary>
  public class SendMailWhenUserDeletedEventHandler : IIntegrationEventHandler<UserDeletedEvent>
  {
    public Task Handle(UserDeletedEvent @event)
    {
      Console.WriteLine($"事件处理：{nameof(SendMailWhenUserDeletedEventHandler)} 用户{@event.UserName}被删除,已发送邮件提醒管理员！");
      return Task.CompletedTask;
    }
  }
}
